<!DOCTYPE html>
<script src="lodash.js"></script>
<script>
  const _ = window._;

  function getSun(a, b, c) {
    return a + b + c;
  }

  const curried = _.curry(getSun);
  console.log(curried(1))

  const curry = func => function curriedFn(...args) {
    // 判断实参和形参的个数
    if(args.length < func.length) {
      return (...rest) => {
        return curriedFn(...args.concat(rest))
      }
    }
    return func(...args)
  }
  // function curry(func) {
  //   return function curriedFn(...args) {
  //     if(args.length < func.length) {
  //       return function() {
  //         return curriedFn(...args.concat(Array.from(arguments)));
  //       }
  //     }
  //     return func(...args);
  //   }
  // }

  const curried2 = curry(getSun);
  console.log(curried2(1))
  console.log(curried2(1)(2, 3))
  console.log(curried2(1)(2)(3))
</script>